package com.jdls.day14.work;

import java.io.*;
import java.util.ArrayList;

/**
 * @author 嘉德罗斯
 * @date 2021/8/4
 */
public class Test4 {
    public static void main(String[] args) throws IOException {
        //6. 使用IO流，把出师表按照编号调整好顺序：（自己定义一个txt文档将下面的数据剪切进去）
        dome1();
    }

    private static void dome1() throws IOException {
        BufferedReader br = new BufferedReader(new FileReader("jdls-class\\src\\com\\jdls\\day14\\work\\a.txt"));
        String a;
        ArrayList<String> list = new ArrayList<>();
        while ((a = br.readLine()) != null) {
            list.add(a);
        }
        BufferedWriter bw = new BufferedWriter(new FileWriter("jdls-class\\src\\com\\jdls\\day14\\work\\a.txt"));
        dome2(bw, list);
        br.close();
        bw.close();
    }

    static int i = 49;

    private static void dome2(BufferedWriter bw, ArrayList<String> list) throws IOException {
        if (list != null) {
            for (String s : list) {
                int a =s.charAt(0);
                if (i == a){
                    bw.write(s);
                    bw.newLine();
                    list.remove(s);
                    bw.flush();
                    break;
                }
            }
            i++;
            if(i<58){
                dome2(bw, list);
            }
            return;
        }
    }
}
